General Outline (with objectives)

WHEN a) Year Map Overview (each colors based off of year, plus Shiny app (filter for years)) b) Stacked Bar Chart of Each Year (each season as different colors)

WHERE c) Three Jurisdictions Map Overview (different colors based off of the three tree giveaway distribution) d) Bar Chart (different colors based of the locations with count) e) Baltimore Neighborhood Map Overview (different colors based off of density of the plantings) f) Bar Chart Highlighting Top 10 Planted Neighborhoods (different colors based off of neighborhood), plus aggregating the rest as Other g) Census Tract Overview in Baltimore (different colors based off of density of the plantings) h) Census Tract Overview in Baltimore County (different colors based off of density of the plantings) i) Bar Graph highlighting Top 10 Locations Planted (Cleaned)

WHAT j) Map Overview of Top 10 Species (each species as a different color) k) Stacked Bar Chart (Highlighting the different species for each one) l) Map Overview of Top 5 Species each Season (each species as a different color, RShiny) m) Bar Graph of Top 5 Species for Each Year (each species as a color)

WHO l) Map Overview with Planting to Redline Zones (RShiny with Year) m) Map Overview with Planting to CBT Zones (RShiny with Year)

0 load libraries and read in data—-

# List all of your packages here

knitr::opts_chunk$set(echo = TRUE)

packs <-c(
            'janitor'    # cleans things up, also pipe-friendly cross-tabulations
           , 'sf'         # for spatial data support
          , 'tidyverse'  # cuz
          , 'tidylog'    # prints out what was done in dplyr and tidyr
          , 'magrittr'   # for the pipe
          , 'mapview'    # web maps for zooming and panning around
          #, 'beepr'      # makes noise when things are done!
          , 'tictoc'     # timing things.
          , 'raster'
          # , 'doParallel' # does what is says! PARALLEL
          # 'broom.mixed',# tidiers for mixed models AND nlme::gls()
          # , 'lubridate'   # DATES!
          , 'tidycensus' # tidy census package
          , 'tidygeocoder' # geo coding
          , 'leaflet' #creating the interactive mapping elements (more specific)
          , 'shiny'
          , 'leafsync'  # linked maps
          , 'DT' 
          )     

# IF the packages in 'packs' are not already installed, install them
# OTHERWISE do NOTHING
if (length(setdiff(packs, rownames(installed.packages()))) > 0) {
install.packages(setdiff(packs, rownames(installed.packages())))
}

# lapply(packs, library, character.only = TRUE)
# this actually loads them with library(package_name)
vapply(packs, library, character.only = TRUE, logical(1), logical.return = TRUE, quietly = TRUE)
##      janitor           sf    tidyverse      tidylog     magrittr      mapview 
##         TRUE         TRUE         TRUE         TRUE         TRUE         TRUE 
##       tictoc       raster   tidycensus tidygeocoder      leaflet        shiny 
##         TRUE         TRUE         TRUE         TRUE         TRUE         TRUE 
##     leafsync           DT 
##         TRUE         TRUE
# # for tidycensus
# setting for get_acs
census_api_key('58fc555c77c229747ade7d9fe50e7c71297cf91a', install = TRUE, overwrite = TRUE)
## [1] "58fc555c77c229747ade7d9fe50e7c71297cf91a"
readRenviron("~/.Renviron")
options(tigris_use_cache = TRUE)
## B get census data

vars21 <- tidycensus::load_variables('acs5', year = 2021)
# vars21 |> View()


my_vars <- c(  'pop'      = 'B01001_001'
             , 'medhhinc' = 'B19013_001'
             )


(MD <-
  tidycensus::get_acs(
      geography = 'state'
    , state = 'MD'
    , variables = my_vars
    , year = 2021
    , geometry = TRUE
    , output = 'wide'
    , moe_level = 95
    ) |>
   st_transform(crs = st_crs(4326)))
## Getting data from the 2017-2021 5-year ACS
## Simple feature collection with 1 feature and 6 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -79.48765 ymin: 37.91172 xmax: -75.04894 ymax: 39.72304
## Geodetic CRS:  WGS 84
##   GEOID     NAME    popE popM medhhincE medhhincM
## 1    24 Maryland 6148545   NA     91431  679.1489
##                         geometry
## 1 MULTIPOLYGON (((-76.05015 3...
mapview(MD)
(cbg <-
  tidycensus::get_acs(
      geography = 'block group'
    , state = 'MD'
    , county = c('Baltimore City', 'Baltimore County')
    , variables = my_vars
    , year = 2021
    , geometry = TRUE
    , output = 'wide'
    , moe_level = 95
    ) |>
    st_transform(crs = st_crs(MD)) |>
    mutate(jurisdiction = case_when(
      str_like(GEOID, '24510%') ~ "Baltimore City",
      str_like(GEOID, '24005%') ~ "Baltimore County",
      TRUE ~ "Neither"
    )))
## Getting data from the 2017-2021 5-year ACS
## mutate: new variable 'jurisdiction' (character) with 2 unique values and 0% NA
## Simple feature collection with 1180 features and 7 fields
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: -76.89556 ymin: 39.19541 xmax: -76.32143 ymax: 39.7212
## Geodetic CRS:  WGS 84
## First 10 features:
##           GEOID                                                            NAME
## 1  245100302001       Block Group 1, Census Tract 302, Baltimore city, Maryland
## 2  245100907003       Block Group 3, Census Tract 907, Baltimore city, Maryland
## 3  245102101002      Block Group 2, Census Tract 2101, Baltimore city, Maryland
## 4  245100702001       Block Group 1, Census Tract 702, Baltimore city, Maryland
## 5  245101508004      Block Group 4, Census Tract 1508, Baltimore city, Maryland
## 6  240054301042 Block Group 2, Census Tract 4301.04, Baltimore County, Maryland
## 7  240054008002    Block Group 2, Census Tract 4008, Baltimore County, Maryland
## 8  245101503003      Block Group 3, Census Tract 1503, Baltimore city, Maryland
## 9  245101507021   Block Group 1, Census Tract 1507.02, Baltimore city, Maryland
## 10 240054909001    Block Group 1, Census Tract 4909, Baltimore County, Maryland
##    popE     popM medhhincE medhhincM                       geometry
## 1   904 302.6383     48594  40679.83 MULTIPOLYGON (((-76.60643 3...
## 2   868 644.5957     55513  45449.36 MULTIPOLYGON (((-76.59894 3...
## 3  1577 411.0638     81944  19416.51 MULTIPOLYGON (((-76.63267 3...
## 4   986 676.7660        NA        NA MULTIPOLYGON (((-76.58105 3...
## 5  1296 704.1702     45659  35710.13 MULTIPOLYGON (((-76.68275 3...
## 6  1440 735.1489        NA        NA MULTIPOLYGON (((-76.64102 3...
## 7   904 270.4681     81172  31271.83 MULTIPOLYGON (((-76.73352 3...
## 8   252 128.6809     57672  49836.43 MULTIPOLYGON (((-76.65999 3...
## 9  1121 400.3404     44355  18785.02 MULTIPOLYGON (((-76.66609 3...
## 10  399 331.2340        NA        NA MULTIPOLYGON (((-76.58763 3...
##        jurisdiction
## 1    Baltimore City
## 2    Baltimore City
## 3    Baltimore City
## 4    Baltimore City
## 5    Baltimore City
## 6  Baltimore County
## 7  Baltimore County
## 8    Baltimore City
## 9    Baltimore City
## 10 Baltimore County
# # examples / double checks
# mapview(baci, zcol = 'popE') +
#   mapview(  MD
#           , color = 'black'
#           , lwd = 1
#           , alpha.regions = 0)
# 
# pop_map <- mapview(baci, zcol = 'popE')
# inc_map <- mapview(baci, zcol = 'medhhincE')
# 
# sync(pop_map, inc_map)

# county <-
#   cbg |>
#   summarize() #this is dissolve

1 Reading in the data visually as a map and cleaning

# Tree Tribble
species_data <- 
  tribble(
  ~common_name,        ~genus_species,            ~itree,
  "Hackberry",         "Celtis occidentalis",     "CEOC",
  "Willow Oak",        "Quercus phellos",         "QUPH",
  "Black Gum",         "Nyssa sylvatica",         "NYSY",
  "Eastern Redbud",    "Cercis canadensis",       "CECA",
  "Sassafras",         "Sassafras albidum",       "SAAL",
  "Chestnut Oak",      "Quercus prinus",          "QUPR",
  "Eastern Red Cedar", "Juniperus virginiana",    "JUVI",
  "Bald Cypress",      "Taxodium distichum",      "TADI",
  "Black Oak",         "Quercus velutina",        "QUVE",
  "American Holly",    "Ilex opaca",              "ILOP",
  "Sweetbay Magnolia", "Magnolia virginiana",     "MAVI",
  "American Sweetgum", "Liquidambar styraciflua", "LIST",
  "Bur Oak",           "Quercus macrocarpa",      "QUMA1",
  "Black Chokeberry",  "Aronia melanocarpa",      "ARME6",
  "Blackhaw Viburnum", "Viburnum prunifolium",    "VIPR",
  "Gingko",            "Ginkgo biloba",            "GIBI",
  "American Persimmon", "Diospyros virginiana",    "DIVI",
  "Flowering Cherry",   "Prunus yedoensis",        "PRYE",
  "Post Oak",           "Quercus stellata",        "QUST",
  "Chinkapin Oak",      "Quercus muehlenbergii",   "QUMU",
  "Tulip Poplar",       "Liriodendron tulipifera", "LITU",
  "Shortleaf Pine",     "Pinus echinata",          "PIEC",
  "Eastern White Pine", "Pinus americana",         "PIST",
  "Yellow Birch",       "Betula alleghaniensis",   "BEAL2",
  "American Yellowwood","Cladrastis luteau",       "CLLU",
  "Smooth Service Berry","Amelanchier laevis",     "AMLA",
  "Boxelder Maple",    "Acer negundo",             "ACNE",
  "American Linden",   "Tilia americana",          "TIAMRE",
  "American Plum",     "Prunus americana",         "PRAM"
  )
  
# Loading data
bwb_total_giveaway <-
  read_csv("output_data/bwb_giveaway_total_final_2024-05-13.csv") |>
  filter(!is.na(lat)) |> #Good double check
  st_as_sf(coords = c("long","lat"), crs = 4326) |> 
  st_join(cbg) |> 
  mutate(common_name = case_when(
    common_name == "Boxelder" ~ "Boxelder Maple",
    common_name == "Yoshino Flowering Cherry" ~ "Flowering Cherry",
    common_name == "Black Tupelo" ~ "Black Gum",
    common_name == "Chinquapin" ~ "Chinkapin Oak",
    common_name == "Breakfast" ~ "Other",
    common_name == "Blackhaw Vibernum" ~ "Blackhaw Viburnum",
    common_name == "Ginkgo" ~ "Gingko",
    TRUE ~ common_name
  )) |>
  filter(address != "822 Montpellier") |> 
  left_join(species_data, by = "common_name") |>
  mutate(
    genus_species = coalesce(genus_species.x, genus_species.y),
    itree = coalesce(itree.x, itree.y)
  ) |>
  dplyr::select(-genus_species.x, -genus_species.y, -itree.x, -itree.y) |>
  left_join(species_data, by = "genus_species") |>
  mutate(
    common_name = coalesce(common_name.x, common_name.y),
    itree = coalesce(itree.x, itree.y)
  ) |>
  dplyr::select(-common_name.x, -common_name.y, -itree.x, -itree.y) |>
 mutate(genus_species = ifelse(common_name == "Other", "Other", genus_species),
       itree = ifelse(common_name == "Other", NA_character_, itree))

2 Creating multiple maps with corresponding graph

A General Map

3 Performing the a-spatial double checks

A Time

# Playing with year (result is season wide)
bwb_total_giveaway |> 
  st_drop_geometry() |>
  tabyl(year, season) |>
  as_tibble() |>
  DT::datatable()
# Same data, different shape (result is time long)
(giveaway_counts_season_year <-
  bwb_total_giveaway |> 
  st_drop_geometry() |>
  group_by(year, season) |>
  count())
## group_by: 2 grouping variables (year, season)
## count: now 20 rows and 3 columns, 2 group variables remaining (year, season)
## # A tibble: 20 × 3
## # Groups:   year, season [20]
##     year season     n
##    <dbl> <chr>  <int>
##  1  2013 Fall      43
##  2  2013 Spring    86
##  3  2014 Fall     111
##  4  2014 Spring   107
##  5  2015 Fall     278
##  6  2015 Spring   192
##  7  2016 Fall     256
##  8  2016 Spring   308
##  9  2017 Fall     399
## 10  2017 Spring   720
## 11  2018 Fall     255
## 12  2018 Spring  1274
## 13  2019 Fall     531
## 14  2019 Spring  1186
## 15  2021 Fall     440
## 16  2021 Spring   564
## 17  2022 Fall     426
## 18  2022 Spring   533
## 19  2023 Fall     562
## 20  2023 Spring   731
# Graphing this giveaway counts
giveaway_counts_season_year |>
  ggplot(aes(x = year, y = n, color = season)) +
  geom_point() +
  # geom_line() +
  geom_smooth(method = "lm") +
  geom_smooth()
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

#geom_sf is for vector spatial data, data is the first argument, matters when you have layers. In terms of the ggplot, aes defines the conditions of the graph (let's you pass it through each point). geom_point makes the point graph. ggplot can be seen as global 

#NULL Lets you always rull

# Graph about time
giveaway_counts_season_year |>
  ggplot(aes(x = as.factor(year), y = n, color = season, group = season)) +
  geom_point() +
  geom_line() +
  labs(
      title = "Number of Tree Giveaways by Year"
    , subtitle = "The Blue Water Baltimore data is also looking at specific seasons"
    , caption = "Testing"
    , x = "Year"
    , y = "Number of Trees Given Away"
  ) +
  theme_bw(16) +
  theme(legend.position = c(.1, .7)) +
  NULL

B Location

glimpse(bwb_total_giveaway)
## Rows: 9,002
## Columns: 24
## $ giveaway_location <chr> "Winand ES", "Winand ES", "Winand ES", "Winand ES", …
## $ year              <dbl> 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013…
## $ season            <chr> "Spring", "Spring", "Spring", "Spring", "Spring", "S…
## $ date              <dttm> 2013-04-25, 2013-04-25, 2013-04-25, 2013-04-25, 201…
## $ address           <chr> "4505 Hawksbury Road", "4708 Three Oaks Road", "4708…
## $ city              <chr> "Pikesville", "Pikesville", "Pikesville", "Owings Mi…
## $ state             <chr> "MD", "MD", "MD", "MD", "MD", "MD", "MD", "MD", "MD"…
## $ zip_code          <dbl> 21208, 21208, 21208, 21133, 21208, 21208, 21208, 211…
## $ county            <chr> "Baltimore County", "Baltimore County", "Baltimore C…
## $ first_name        <chr> "Karen", "Makayla", "Makayla", "Al", "Balinda", "Bal…
## $ last_name         <chr> "James", "Hill", "Hill", "Brown", "Oliver", "Oliver"…
## $ phone             <chr> "410-602-2089", "410-963-6512", "410-963-6512", "678…
## $ email             <chr> "koceysmommie@aolo.com", "panhill2000@yahoo.com", "p…
## $ geometry          <POINT [°]> POINT (-76.75174 39.37312), POINT (-76.7598 39…
## $ GEOID             <chr> "240054026041", "240054026042", "240054026042", "240…
## $ NAME              <chr> "Block Group 1, Census Tract 4026.04, Baltimore Coun…
## $ popE              <dbl> 4172, 2304, 2304, 2078, 4172, 4172, 4172, 2637, 2504…
## $ popM              <dbl> 1196.2553, 906.7234, 906.7234, 899.5745, 1196.2553, …
## $ medhhincE         <dbl> 102434, 108264, 108264, 78359, 102434, 102434, 10243…
## $ medhhincM         <dbl> 37537.87, 28624.34, 28624.34, 55193.36, 37537.87, 37…
## $ jurisdiction      <chr> "Baltimore County", "Baltimore County", "Baltimore C…
## $ genus_species     <chr> "Amelanchier sp.", "Quercus phellos", "Amelanchier s…
## $ common_name       <chr> "Serviceberry", "Willow Oak", "Serviceberry", "Willo…
## $ itree             <chr> "AM", "QUPH", "AM", "QUPH", "QUPH", "QURU", "QUPH", …
bwb_total_giveaway |>
  st_drop_geometry() |>
  tabyl(giveaway_location)
##                   giveaway_location    n      percent valid_percent
##          32nd Street Farmers Market  168 0.0186625194  0.0340149828
##                            Anneslie   12 0.0013330371  0.0024296416
##            Cherry Hill Urban Garden   24 0.0026660742  0.0048592833
##                       Chestnut Hill    4 0.0004443457  0.0008098805
##    Cromwell Valley Harvest Festival   62 0.0068873584  0.0125531484
##                Cromwell Valley Park   43 0.0047767163  0.0087062158
##                    Forestry Nursery   61 0.0067762719  0.0123506783
##                                GFLP   38 0.0042212842  0.0076938652
##         Gateway Park at Darley Park   14 0.0015552100  0.0028345819
##         Greektown - John Ruhrah EMS   55 0.0061097534  0.0111358575
##            Gwynns Falls Leakin Park   63 0.0069984448  0.0127556185
##            Gwynns Falls/Leakin Park  114 0.0126638525  0.0230815955
##                 Herring Run Nursery 1260 0.1399688958  0.2551123709
##                  JFX Farmers Market  146 0.0162186181  0.0295606398
##    Langston Hughes Community Center   17 0.0018884692  0.0034419923
##                        REI Timonium   90 0.0099977783  0.0182223122
##                          Ridgeleigh    9 0.0009997778  0.0018222312
##                  Ridgely Manor Park  354 0.0393245945  0.0716744280
##                        Rogers Forge    8 0.0008886914  0.0016197611
##         St Matthews Catholic Church   32 0.0035547656  0.0064790443
##    Stillmeadow Community Fellowship 2152 0.2390579871  0.4357157319
##                          Stoneleigh    8 0.0008886914  0.0016197611
##  Washington Hill Fall Community Day    5 0.0005554321  0.0010123507
##                         West Towson   87 0.0096645190  0.0176149018
##                          Westy Walk   79 0.0087758276  0.0159951407
##                           Winand ES   34 0.0037769385  0.0068839846
##                                <NA> 4063 0.4513441457            NA

C Species

#Genus Species
bwb_total_giveaway |>
  st_drop_geometry() |>
  tabyl(genus_species) 
##            genus_species   n      percent
##             Acer negundo   8 0.0008886914
##              Acer rubrum 110 0.0122195068
##         Acer saccharinum   6 0.0006665186
##           Acer saccharum  18 0.0019995557
##   Aesculus hippocastanum   1 0.0001110864
##      Aesculus parviflora   1 0.0001110864
##           Aesculus pavia  29 0.0032215063
##          Alnus serrulata  12 0.0013330371
##   Amelanchier canadensis 164 0.0182181737
##       Amelanchier laevis  16 0.0017773828
##          Amelanchier sp. 648 0.0719840036
##       Aronia melanocarpa  48 0.0053321484
##          Asimina triloba 544 0.0604310153
##    Betula alleghaniensis  36 0.0039991113
##             Betula lenta   5 0.0005554321
##             Betula nigra 206 0.0228838036
##     Carpinus caroliniana 295 0.0327704954
##             Carya glabra  34 0.0037769385
##      Carya illinoinensis  33 0.0036658520
##          Carya laciniosa  22 0.0024439014
##  Casuarina equisetifolia  25 0.0027771606
##      Celtis occidentalis  95 0.0105532104
##        Cercis canadensis 300 0.0333259276
##   Chamaecyparis thyoides   9 0.0009997778
##   Chionanthus virginicus  57 0.0063319262
##     Cladrastis kentuckea  55 0.0061097534
##      Cladrastis kentukea  36 0.0039991113
##        Cladrastis luteau   5 0.0005554321
##      Cornus alterniflora   3 0.0003332593
##      Cornus alternifolia  34 0.0037769385
##           Cornus florida 198 0.0219951122
##        Corylus americana 162 0.0179960009
##    Crataegus phaenopyrum   5 0.0005554321
##      Diospyros viginiana  57 0.0063319262
##     Diospyros virginiana 380 0.0422128416
##        Fagus grandifolia  48 0.0053321484
##             Ficus carica 325 0.0361030882
##            Ginkgo biloba  92 0.0102199511
##      Gymnocladus dioicus   1 0.0001110864
##     Gymnocladus dioicusa  30 0.0033325928
##     Hamamelis virginiana 177 0.0196622973
##               Ilex opaca 307 0.0341035325
##     Juniperus virginiana 170 0.0188846923
##        Lagerstroemia sp.   1 0.0001110864
##  Liquidambar styraciflua  66 0.0073317041
##  Liriodendron tulipifera  87 0.0096645190
##     Magnolia grandiflora  45 0.0049988891
##      Magnolia virginiana 546 0.0606531882
##          Nyssa sylvatica 301 0.0334370140
##        Ostrya virginiana  19 0.0021106421
##                    Other  47 0.0052210620
##           Pinus echinata  26 0.0028882471
##             Pinus rigida  49 0.0054432348
##            Pinus strobus 135 0.0149966674
##              Pinus taeda  74 0.0082203955
##         Pinus virginiana  49 0.0054432348
##         Platanus hybrida   2 0.0002221729
##    Platanus occidentalis 180 0.0199955565
##        Populus deltoides 134 0.0148855810
##         Prunus americana 322 0.0357698289
##      Prunus angustifolia  25 0.0027771606
##          Prunus maritima   9 0.0009997778
##          Prunus serotina 106 0.0117751611
##         Prunus serrulata   4 0.0004443457
##         Prunus yedoensis   4 0.0004443457
##             Quercus alba 215 0.0238835814
##          Quercus bicolor 131 0.0145523217
##         Quercus coccinea  33 0.0036658520
##          Quercus falcata  85 0.0094423461
##       Quercus ilicifolia   1 0.0001110864
##       Quercus macrocarpa 125 0.0138858032
##      Quercus marilandica   2 0.0002221729
##        Quercus michauxii  48 0.0053321484
##          Quercus montana  19 0.0021106421
##    Quercus muehlenbergii  51 0.0056654077
##        Quercus palustris  38 0.0042212842
##          Quercus phellos 185 0.0205509887
##           Quercus prinus  67 0.0074427905
##            Quercus rubra 110 0.0122195068
##         Quercus stellata  30 0.0033325928
##         Quercus velutina  27 0.0029993335
##     Robinia pseudoacacia   6 0.0006665186
##              Salix nigra   1 0.0001110864
##      Sambucus canadensis 253 0.0281048656
##           Sambucus nigra  26 0.0028882471
##        Sassafras albidum 168 0.0186625194
##       Taxodium distichum 233 0.0258831371
##       Thuja occidentalis   3 0.0003332593
##          Tilia americana  47 0.0052210620
##          Ulmus americana   8 0.0008886914
##     Viburnum prunifolium  51 0.0056654077
##         prunus_americana   1 0.0001110864
#Common Name
(giveaway_counts_common_name <-
  bwb_total_giveaway |>
  st_drop_geometry() |>
  tabyl(common_name) |>
  as_tibble() |>
  arrange(desc(n))
)
## # A tibble: 84 × 3
##    common_name            n percent
##    <chr>              <int>   <dbl>
##  1 Serviceberry         812  0.0902
##  2 Sweetbay Magnolia    546  0.0607
##  3 Pawpaw               544  0.0604
##  4 American Persimmon   437  0.0485
##  5 Common Fig           325  0.0361
##  6 American Plum        323  0.0359
##  7 American Holly       307  0.0341
##  8 Black Gum            301  0.0334
##  9 Eastern Redbud       300  0.0333
## 10 American Hornbeam    295  0.0328
## # ℹ 74 more rows
bwb_total_giveaway |>
  filter(is.na(common_name) | is.na(genus_species))
## filter: removed all rows (100%)
## Simple feature collection with 0 features and 23 fields
## Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS:  WGS 84
## # A tibble: 0 × 24
## # ℹ 24 variables: giveaway_location <chr>, year <dbl>, season <chr>,
## #   date <dttm>, address <chr>, city <chr>, state <chr>, zip_code <dbl>,
## #   county <chr>, first_name <chr>, last_name <chr>, phone <chr>, email <chr>,
## #   geometry <GEOMETRY [°]>, GEOID <chr>, NAME <chr>, popE <dbl>, popM <dbl>,
## #   medhhincE <dbl>, medhhincM <dbl>, jurisdiction <chr>, genus_species <chr>,
## #   common_name <chr>, itree <chr>
#Making that
bwb_total_giveaway |>
  filter(is.na(common_name) & is.na(genus_species))
## filter: removed all rows (100%)
## Simple feature collection with 0 features and 23 fields
## Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
## Geodetic CRS:  WGS 84
## # A tibble: 0 × 24
## # ℹ 24 variables: giveaway_location <chr>, year <dbl>, season <chr>,
## #   date <dttm>, address <chr>, city <chr>, state <chr>, zip_code <dbl>,
## #   county <chr>, first_name <chr>, last_name <chr>, phone <chr>, email <chr>,
## #   geometry <GEOMETRY [°]>, GEOID <chr>, NAME <chr>, popE <dbl>, popM <dbl>,
## #   medhhincE <dbl>, medhhincM <dbl>, jurisdiction <chr>, genus_species <chr>,
## #   common_name <chr>, itree <chr>

D Making the count by city

(giveaway_counts_city_season <-
  bwb_total_giveaway |>
  st_drop_geometry() |>
  group_by(city, year, season) |>
  count() |>
  as_tibble() |>
  arrange(desc(n))
)
## group_by: 3 grouping variables (city, year, season)
## count: now 349 rows and 4 columns, 3 group variables remaining (city, year, season)
## # A tibble: 349 × 4
##    city       year season     n
##    <chr>     <dbl> <chr>  <int>
##  1 Baltimore  2018 Spring  1125
##  2 Baltimore  2019 Spring  1067
##  3 Baltimore  2023 Spring   665
##  4 Baltimore  2019 Fall     531
##  5 Baltimore  2023 Fall     528
##  6 Baltimore  2017 Spring   466
##  7 Baltimore  2017 Fall     317
##  8 Baltimore  2021 Spring   297
##  9 Baltimore  2022 Spring   262
## 10 Baltimore  2021 Fall     247
## # ℹ 339 more rows
giveaway_counts_city_season |>
  ggplot(aes(year, n, color = season, group = season)) +
  geom_point() +
  geom_line() +
  facet_wrap(~city) +
  theme_bw(16) +
  NULL
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

## 
  bwb_total_giveaway |>
  st_drop_geometry() |>
  group_by(zip_code, year, season) |>
  count() |>
  as_tibble() |>
  arrange(desc(n)) |>
  ggplot(aes(year, n, color = season, group = season)) +
  geom_point() +
  geom_line() +
  facet_wrap(~zip_code) +
  theme_bw(16) +
  NULL
## group_by: 3 grouping variables (zip_code, year, season)
## count: now 765 rows and 4 columns, 3 group variables remaining (zip_code, year, season)
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?`geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

## Comparing to county data
  bwb_total_giveaway |>
  st_drop_geometry() |>
  group_by(county, year, season) |>
  count() |>
  as_tibble() |>
  arrange(desc(n)) |>
  ggplot(aes(year, n, color = season, group = season)) +
  geom_point() +
  geom_line() +
  facet_wrap(~county) +
  theme_bw(16) +
  theme(axis.text.x = element_text(angle = 90, vjust = .5)) +
  NULL
## group_by: 3 grouping variables (county, year, season)
## count: now 57 rows and 4 columns, 3 group variables remaining (county, year, season)

4 maps and graphs to make

# Species over time
# graph with time on horizontal
# vertical is amount
# color for season
# lines per species (too many)
bwb_total_giveaway |> 
  st_drop_geometry() |> 
  group_by(year, season, common_name) |> 
  count() |> # summary() # n ranges from 1 to 192
  filter(n > 10) |> 
  ggplot(aes(year, n, group = common_name, color = season)) +
  geom_point() +
  geom_line() +
  facet_wrap(~common_name)
## group_by: 3 grouping variables (year, season, common_name)
## count: now 452 rows and 4 columns, 3 group variables remaining (year, season, common_name)
## filter (grouped): removed 209 rows (46%), 243 rows remaining
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?
## `geom_line()`: Each group consists of only one observation.
## ℹ Do you need to adjust the group aesthetic?

# map for the top five species
five_most_common_species <- 
  bwb_total_giveaway |> 
  st_drop_geometry() |> 
  group_by(common_name) |> 
  count() |> 
  ungroup() |> 
  arrange(desc(n)) |> 
  slice(1:10)
## group_by: one grouping variable (common_name)
## count: now 84 rows and 2 columns, one group variable remaining (common_name)
## ungroup: no grouping variables
## slice: removed 74 rows (88%), 10 rows remaining
bwb_total_giveaway |> 
  filter(common_name %in% five_most_common_species$common_name) |> 
  mapview()
## filter: removed 4,812 rows (53%), 4,190 rows remaining
bwb_total_giveaway |> 
  filter(common_name %in% five_most_common_species$common_name) |> 
  mapview(zcol = 'common_name')
## filter: removed 4,812 rows (53%), 4,190 rows remaining
bwb_total_giveaway |> 
  filter(common_name %in% five_most_common_species$common_name) |> 
  mapview(zcol = 'common_name', layer.name = "Common Name")
## filter: removed 4,812 rows (53%), 4,190 rows remaining
bwb_total_giveaway |> 
  filter(common_name == 'Serviceberry') |> 
  mapview(zcol = 'year', layer.name = "Common Name")
## filter: removed 8,190 rows (91%), 812 rows remaining

old sandbox

```{r eval=FALSE, message=FALSE, include=FALSE} # 5 augment tree data with census

bwb_total_giveaway_aug <- bwb_total_giveaway |> st_join(cbg |> tidylog::select(-NAME) )

bwb_total_giveaway_aug |> glimpse()

bwb_total_giveaway_aug |> mapview(zcol = ‘medhhincE’)

Create an interactive map

bwb_total_giveaway |> mapview()

Messing with data

bwb_total_giveaway |> filter(year == 2015) |> mapview()

Messing with data

bwb_total_giveaway |> mapview(zcol = “year”)

Display the map

map_giveaway

#Final squeaky cleaned geocoded and get the GItHub resolved, and by the wenday. Email how you going. Sit next. Finish it by next Monday: Geocoding and GitHUb Meet by Zoom Tuesdya from 9 to 11